<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="refresh" content="1">
  <!-- 每秒刷新1次 -->
  <meta charset="UTF-8">
  <title>Document</title>
  <style type="text/css">
    .time-item {
      width: 450px;
      height: 45px;
      margin: 0 auto;
    }
    
    .time-item strong {
        background: orange;
        color: #fff;
        line-height: 49px;
        font-size: 36px;
        font-family: Arial;
        padding: 0 10px;
        margin-right: 10px;
        border-radius: 5px;
        box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);
    }

    .time-item > span {
        float: left;
        line-height: 49px;
        color: orange;
        font-size: 32px;
        margin: 0 10px;
        font-family: Arial, Helvetica, sans-serif;
    }
    .title {
      width: 260px;
      height: 50px;
      margin:200px auto 50px auto;
    }
  </style>

</head>
<body>
  <h1 class="title">距离光棍节，还有</h1>
  
  <div class="time-item">
    <span><span id="day">00</span>天</span>
    <strong><span id="hour">00</span>时</strong>
    <strong><span id="minute">00</span>分</strong>
    <strong><span id="second">00</span>秒</strong>
  </div>

  <script>
    // 现在的日期对象  
    // 光棍节的日期对象  
    var gun = new Date('2023-11-11 00:00:00');
    var olds = gun.getTime();
    var now = new Date();
    var news = now.getTime();
    

    var res = olds-news; //毫秒 
    res /=1000 //换算成秒  
    var day,hour,minutes,second;
    day = parseInt(res / (3600*24));
    hour = parseInt(res / 3600 % 24); // 求余(3600*24) 整除 3600 
    minutes =  parseInt(res / 60 % 60); // 求余 3600 整除 60 
    second = parseInt(res % 60);

    // console.log(day,hour,minutes,second);
    // 在这个文档中 找到id是day的 然后给标签中间的内容重新赋值 

    document.getElementById('day').innerHTML = day;
    document.getElementById('hour').innerHTML = hour;
    document.getElementById('minute').innerHTML = minutes;
    document.getElementById('second').innerHTML = second;


  </script>
    
  </body>

  </html>